﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace TaskManager
{
    //"id": "27",
    //"uid": "192",
    //"uaccount": "zheng.yq",
    //"urealname": "郑宇强",
    //"work": "工作内容11",
    //"createTime": "2016-05-13 09:31:47",
    //"markday": "2016-05-13",
    //"dtype": "1",
    //"consumed": "2",
    //"isAchieve": "1",
    //"endTime": "0000-00-00 00:00:00",
    //"dstatus": "1",
    //"leadTime": "2",
    //"tid": "0"

    // 此类用于实现对通用数据信息的解析，可继承该类实现特定逻辑
    public class Data_T
    {
        //public string id, uid, uaccount, urealname, work, createTime, markday, dtype, consumed, isAchieve, endTime, dstatus, leadTime, tid;
        //public string id;

        public Data_T()
        {}

        //将当前对象Type1的数据，转化为Json串  
        public String ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        //从Json串创建Data_T对象  
        public Data_T Parse(string JsonStr)
        {
            return JsonConvert.DeserializeObject<Data_T>(JsonStr);
        }

        // 数组的反序列化，返回Data_T数组
        public static List<Data_T> Iteams(string JsonStr)
        {
            List<Data_T> iteams = JsonConvert.DeserializeObject<List<Data_T>>(JsonStr);
            return iteams;
        }
    }



    // 此类用于实现对提示信息的解析
    public class Data_Remind
    {
        public string id, uid, uaccount, urealname, title, content, sendAccount, sendTime, createTime, isSend, sendDept, period;

        public Data_Remind()
        {}

        //将当前对象Type1的数据，转化为Json串  
        public String ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        //从Json串创建Type1对象  
        public static Data_Remind Parse(string JsonStr)
        {
            return JsonConvert.DeserializeObject<Data_Remind>(JsonStr);
        }

        // 数组的反序列化，返回Data_daily数组
        public static List<Data_Remind> Iteams(string JsonStr)
        {
            try
            {
                List<Data_Remind> iteams = JsonConvert.DeserializeObject<List<Data_Remind>>(JsonStr);
                return iteams;
            }
            catch (Exception e) { return new List<Data_Remind>(); }
        }
    }

    // 此类用于实现对任务信息的解析
    public class Data_Task
    {
        public string id, project, module, story, storyVersion, fromBug, name, type, pri, estimate, consumed, left, deadline, status, mailto, desc, openedBy, openedDate, assignedTo, assignedDate, estStarted, realStarted, finishedBy, finishedDate, canceledBy, canceledDate, closedBy, closedDate, closedReason, lastEditedBy, lastEditedDate, deleted;

        public Data_Task()
        {}

        //将当前对象Data_Task的数据，转化为Json串  
        public String ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        //从Json串创建Data_Task对象  
        public static Data_Task Parse(string JsonStr)
        {
            return JsonConvert.DeserializeObject<Data_Task>(JsonStr);
        }

        // 数组的反序列化，返回Data_Task数组
        public static List<Data_Task> Iteams(string JsonStr)
        {
            try
            {
                List<Data_Task> iteams = JsonConvert.DeserializeObject<List<Data_Task>>(JsonStr);
                return iteams;
            }
            catch (Exception e) { return new List<Data_Task>(); }
        }
    }

    // 此类用于实现对需求信息的解析
    public class Data_Demand
    {
        public string id, product, branch, module, plan, source, fromBug, title, keywords, type, pri, estimate, status, stage, mailto, openedBy, openedDate, assignedTo, assignedDate, lastEditedBy, lastEditedDate, reviewedBy, reviewedDate, closedBy, closedDate, closedReason, toBug, childStories, linkStories, duplicateStory, version, deleted;

        public Data_Demand()
        {}

        //将当前对象Data_Demand的数据，转化为Json串  
        public String ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        //从Json串创建Data_Demand对象  
        public static Data_Demand Parse(string JsonStr)
        {
            return JsonConvert.DeserializeObject<Data_Demand>(JsonStr);
        }

        // 数组的反序列化，返回Data_Demand数组
        public static List<Data_Demand> Iteams(string JsonStr)
        {
            try
            {
                List<Data_Demand> iteams = JsonConvert.DeserializeObject<List<Data_Demand>>(JsonStr);
                return iteams;
            }
            catch (Exception e) { return new List<Data_Demand>(); }
        }
    }


    // 此类用于实现对，测试信息的解析
    public class Data_Testtask
    {
        public string id, name, product, project, build, owner, pri, begin, end, mailto, desc, report, status, deleted;

        public Data_Testtask()
        {}

        //将当前对象Type1的数据，转化为Json串  
        public String ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        //从Json串创建Data_Testtask对象  
        public Data_Testtask Parse(string JsonStr)
        {
            return JsonConvert.DeserializeObject<Data_Testtask>(JsonStr);
        }

        // 数组的反序列化，返回Data_Testtask数组
        public static List<Data_Testtask> Iteams(string JsonStr)
        {
            List<Data_Testtask> iteams = JsonConvert.DeserializeObject<List<Data_Testtask>>(JsonStr);
            return iteams;
        }
    }

    // 此类用于实现对，bug信息的解析
    public class Data_Bug
    {
        public string id, product, branch, module, project, plan, story, storyVersion, task, toTask, toStory, title, keywords, severity, pri, type, os, browser, hardware, found, steps, status, confirmed, activatedCount, mailto, openedBy, openedDate, openedBuild, assignedTo, assignedDate, resolvedBy, resolution, resolvedBuild, resolvedDate, closedBy, closedDate, duplicateBug, linkBug, case_, caseVersion, result, Bug, lastEditedBy, lastEditedDate, deleted;

        public Data_Bug()
        { }

        //将当前对象Type1的数据，转化为Json串  
        public String ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        //从Json串创建Data_Bug对象  
        public Data_Bug Parse(string JsonStr)
        {
            return JsonConvert.DeserializeObject<Data_Bug>(JsonStr);
        }

        // 数组的反序列化，返回Data_Bug数组
        public static List<Data_Bug> Iteams(string JsonStr)
        {
            List<Data_Bug> iteams = JsonConvert.DeserializeObject<List<Data_Bug>>(JsonStr);
            return iteams;
        }
    }

    // 此类用于实现对日志信息的解析
    public class Data_Daily
    {
        public string id, uid, uaccount, urealname, work, createTime, markday, dtype, consumed, isAchieve, endTime, dstatus, leadTime, tid;

        public Data_Daily()
        {
        }

        //将当前对象Type1的数据，转化为Json串  
        public String ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        //从Json串创建Type1对象  
        public static Data_Daily Parse(string JsonStr)
        {
            return JsonConvert.DeserializeObject<Data_Daily>(JsonStr);
        }

        // 数组的反序列化，返回Data_daily数组
        public static List<Data_Daily> Iteams(string JsonStr)
        {
            List<Data_Daily> iteams = JsonConvert.DeserializeObject<List<Data_Daily>>(JsonStr);
            return iteams;
        }
    }

    // 此类用于实现对点餐信息的解析
    public class Data_Food
    {
        public string id, foid, uid, uaccount, date, food;

        public Data_Food()
        { }

        //将当前对象Data_Food的数据，转化为Json串  
        public String ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        //从Json串创建Data_Food对象  
        public static Data_Food Parse(string JsonStr)
        {
            return JsonConvert.DeserializeObject<Data_Food>(JsonStr);
        }

        // 数组的反序列化，返回Data_Food数组
        public static List<Data_Food> Iteams(string JsonStr)
        {
            try
            {
                List<Data_Food> iteams = JsonConvert.DeserializeObject<List<Data_Food>>(JsonStr);
                return iteams;
            }
            catch (Exception e) { return new List<Data_Food>(); }
        }
    }

    // 此类用于实现对日志信息的解析
    public class Data_AllTab
    {
        public List<Data_Task> task;        // 任务
        public List<Data_Demand> story;     // 需求
        public List<Data_Testtask> test;    // 测试
        public List<Data_Bug> bug;          // bug
        public List<Data_Daily> daily;      // 日记
        public List<Data_Remind> message;   // 定时信息

        public Data_AllTab()
        {
        }

        //将当前对象Data_AllTab的数据，转化为Json串  
        public String ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        //将当前对象value，转化为Json串  
        public static String ToJson(object value)
        {
            return JsonConvert.SerializeObject(value);
        }

        //从Json串创建Data_AllTab对象  
        public static Data_AllTab Parse(string JsonStr)
        {
            return JsonConvert.DeserializeObject<Data_AllTab>(JsonStr);
        }

        // 数组的反序列化，返回Data_AllTab数组
        public static List<Data_AllTab> Iteams(string JsonStr)
        {
            List<Data_AllTab> iteams = JsonConvert.DeserializeObject<List<Data_AllTab>>(JsonStr);
            return iteams;
        }
    }

    public class Id
    {
        public string id;
        public Id(string id) 
        {
            this.id = id;
        }

        //将当前对象Type1的数据，转化为Json串  
        public String ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        // 数组的反序列化，返回Data_daily数组
        public static String ToJson(List<Id> Iteams)
        {
            return JsonConvert.SerializeObject(Iteams);
        }

        //从Json串创建Id对象  
        public static Id Parse(string JsonStr)
        {
            return JsonConvert.DeserializeObject<Id>(JsonStr);
        }

        // 数组的反序列化，返回Data_daily数组
        public static List<Id> Iteams(string JsonStr)
        {
            try
            {
                List<Id> iteams = JsonConvert.DeserializeObject<List<Id>>(JsonStr);
                return iteams;
            }
            catch (Exception e) { return new List<Id>(); }
        }
    }

    // 设置信息,用于存储本工具的设置信息
    public class SettingData
    {
        public string useIE_explore = "0";              // 标识是否使用IE浏览器打开
        public string newDaily_showCosumePannel = "0";  // 是否显示耗时控件逻辑
        public int minute_Before_TaskDeadline = 10;     // Task任务截止时间前n分钟时，给出将到期提示信息
        public int second_Refresh_Intervate = 90;       // 任务管理工具获取数据刷新时间间隔
        public string FoodRemind_time = "11:55:00";     // 点餐信息提醒时间， “99：99：99”不提醒

        public SettingData()
        { }

        //将当前对象Type1的数据，转化为Json串  
        public String ToJson()
        {
            try { return JsonConvert.SerializeObject(this); }
            catch (Exception ex)
            {
                return "";
            }
        }

        // 数组的反序列化，返回Data_daily数组
        public static String ToJson(List<SettingData> Iteams)
        {
            return JsonConvert.SerializeObject(Iteams);
        }

        //从Json串创建Id对象  
        public static SettingData Parse(string JsonStr)
        {
            SettingData Iteam = null;
            try
            {
                Iteam = JsonConvert.DeserializeObject<SettingData>(JsonStr);
            }
            catch (Exception ex) { Iteam = new SettingData(); }
            return Iteam;
        }

        // 数组的反序列化，返回Data_daily数组
        public static List<SettingData> Iteams(string JsonStr)
        {
            try
            {
                List<SettingData> iteams = JsonConvert.DeserializeObject<List<SettingData>>(JsonStr);
                return iteams;
            }
            catch (Exception e) { return new List<SettingData>(); }
        }
    }

    // {"version":"20160524","url":"http:\/\/task.joymeng.com\/client.exe"}
    // 此类用于实现对版本信息的解析
    public class Data_Verison
    {
        public string version="0", url="", Info="";
        public bool forceUpdate = true;            // 是否强制更新

        public Data_Verison()
        { }

        //将当前对象Type1的数据，转化为Json串  
        public String ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        //从Json串创建Type1对象  
        public static Data_Verison Parse(string JsonStr)
        {
            return JsonConvert.DeserializeObject<Data_Verison>(JsonStr);
        }

        // 数组的反序列化，返回Data_daily数组
        public static List<Data_Verison> Iteams(string JsonStr)
        {
            try
            {
                List<Data_Verison> iteams = JsonConvert.DeserializeObject<List<Data_Verison>>(JsonStr);
                return iteams;
            }
            catch (Exception e) { return new List<Data_Verison>(); }
        }
    }


    //{"status":1,"start_time":"08:30","end_time":"09:00","second":60}
    public class Data_Screenshot
    {
        public int status = 0;
        public string  start_time = "08:30", end_time = "09:00";
        public int second = 60;
        public bool isDebug = false;

        public Data_Screenshot()
        { }

        //将当前对象Data_Screenshot的数据，转化为Json串  
        public String ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        //从Json串创建Data_Screenshot对象  
        public static Data_Screenshot Parse(string JsonStr)
        {
            try
            {
                return JsonConvert.DeserializeObject<Data_Screenshot>(JsonStr);
            }
            catch (Exception e) 
            { 
                return new Data_Screenshot(); 
            }
        }

        // 数组的反序列化，返回Data_daily数组
        public static List<Data_Screenshot> Iteams(string JsonStr)
        {
            try
            {
                List<Data_Screenshot> iteams = JsonConvert.DeserializeObject<List<Data_Screenshot>>(JsonStr);
                return iteams;
            }
            catch (Exception e) { return new List<Data_Screenshot>(); }
        }
    }

    // 登录信息
    public class Data_ChecingIn
    {
        public string id, account, realname, date, createDate, nei_ip, wai_ip, version;

        public Data_ChecingIn()
        { }

        //将当前对象Data_ChecingIn的数据，转化为Json串  
        public String ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        //从Json串创建Data_ChecingIn对象  
        public static Data_ChecingIn Parse(string JsonStr)
        {
            return JsonConvert.DeserializeObject<Data_ChecingIn>(JsonStr);
        }

        // 数组的反序列化，返回Data_ChecingIn数组
        public static List<Data_ChecingIn> Iteams(string JsonStr)
        {
            try
            {
                List<Data_ChecingIn> iteams = JsonConvert.DeserializeObject<List<Data_ChecingIn>>(JsonStr);
                return iteams;
            }
            catch (Exception e) { return new List<Data_ChecingIn>(); }
        }
    }

    // 用户信息
    public class Data_User
    {
        public string id, dept, account, password, role, realname, nickname, commiter, avatar, birthday, gender, email, skype, qq, yahoo, gtalk, wangwang, 
            mobile, phone, address, zipcode, join, visits, ip, last, fails, locked, ranzhi, deleted, jobnumber, floornumber;


        public Data_User()
        { }

        //将当前对象Data_User的数据，转化为Json串  
        public String ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        //从Json串创建Data_User对象  
        public static Data_User Parse(string JsonStr)
        {
            return JsonConvert.DeserializeObject<Data_User>(JsonStr);
        }

        // 数组的反序列化，返回Data_User数组
        public static List<Data_User> Iteams(string JsonStr)
        {
            try
            {
                List<Data_User> iteams = JsonConvert.DeserializeObject<List<Data_User>>(JsonStr);
                return iteams;
            }
            catch (Exception e) { return new List<Data_User>(); }
        }
    }

}


//using Newtonsoft.Json;  //VS2013引入： project->Add Reference->Extensions->Json.NET  
  
//namespace JsonProject  
//{  
//    //Json示例，  
//    //string str = new Type1().ToJson();  //{"name":"李明","年龄":23}  
//    //Type1 obj = Type1.Parse(str);       //从json串创建Type1对象  
//    class Type1  
//    {  
//        public string name;  
  
//        [JsonProperty("年龄")] //为age重命名  
//        public int age;  
  
//        [JsonIgnore]           //忽略该属性  
//        public string address;   
  
//        public Type1()   
//        {  
//            name = "李明";  
//            age = 23;  
//            address = "地址xxxx";  
//        }  
  
//        //将当前对象Type1的数据，转化为Json串  
//        public String ToJson()  
//        {  
//            return JsonConvert.SerializeObject(this);  
//        }  
  
//        //从Json串创建Type1对象  
//        public static Type1 Parse(string JsonStr)  
//        {  
//            return JsonConvert.DeserializeObject<Type1>(JsonStr);  
//        } 
 
//        // 数组的反序列化，返回Type1数组List
//        public static List<Type1> Iteams(string JsonStr)
//        {
//            List<Type1> iteams = JsonConvert.DeserializeObject<List<Type1>>(JsonStr);
//            return iteams;
//        }
//    }  
//}  
